﻿namespace HRM.CORE
{
    using DevExpress.XtraEditors;
    using HRM.CORE.CLASS;
    
    using System; using Extra.ERP;
    using System.ComponentModel;
    using System.Drawing;
    using System.Runtime.CompilerServices;
    using System.Windows.Forms; using Common;
    using APP.HELPER.Utils.Language;

    public class xfmTimekeeperTable : XtraForm
    {
        private IContainer components = null;
        public HRM.CORE.xucTimekeeperExtraPrivate xucTimekeeperExtraPrivate;
        public HRM.CORE.xucTimekeeperTable xucTimekeeperTable;
        public HRM.CORE.xucTimekeeperTable1 xucTimekeeperTable1;
        public HRM.CORE.xucTimekeeperTableHour xucTimekeeperTableHour;

        public event ClosedHandler Closed;

        public event TimekeeperTableDeletedHandler TimekeeperTableDeleted;

        public event TimekeeperTableInsertedHandler TimekeeperTableInserted;

        public event UnShiftDataHandler UnShiftData;

        public xfmTimekeeperTable()
        {
            this.InitializeComponent();
            this.Text = MultiLanguages.GetString("tbl_TimekeeperTable", "TimesheetsByMonth", this.Text);
            base.Load += new EventHandler(this.xfmTimekeeperTable_Load);
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            base.SuspendLayout();
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.ClientSize = new Size(0x284, 0x1b2);
            base.Name = "xfmTimekeeperTable";
            this.Text = "Bảng Chấm C\x00f4ng Theo Th\x00e1ng";
            base.FormClosing += new FormClosingEventHandler(this.xfmTimekeeperTable_FormClosing);
            base.ResumeLayout(false);
        }

        private void LoadTimekeeperExtraPrivate()
        {
            this.xucTimekeeperExtraPrivate = new HRM.CORE.xucTimekeeperExtraPrivate();
            this.xucTimekeeperExtraPrivate.Closed += new HRM.CORE.xucTimekeeperExtraPrivate.ClosedHandler(this.xucTimekeeperTable_Closed);
            this.xucTimekeeperExtraPrivate.UnShiftData += (s, m, y) => this.RaiseUnShiftDataHandler(m, y);
            this.xucTimekeeperExtraPrivate.TimekeeperTableDeleted += s => this.RaiseTimekeeperTableDeletedHander();
            this.xucTimekeeperExtraPrivate.TimekeeperTableSelected += delegate (object s, string code, Guid tID, int year, int mSelected) {
                if (mSelected == 0)
                {
                    if (this.xucTimekeeperTable != null)
                    {
                        this.xucTimekeeperTable.BringToFront();
                        this.xucTimekeeperTable.SetTimeKeeperTableList(tID, year);
                        this.xucTimekeeperTable.xucOrganization1.SetFocusedNode(code);
                    }
                    else
                    {
                        this.LoadTimekeeperTable();
                        this.xucTimekeeperTable.SetTimeKeeperTableList(tID, year);
                        this.xucTimekeeperTable.xucOrganization1.SetFocusedNode(code);
                    }
                }
                else if (mSelected == 1)
                {
                    if (this.xucTimekeeperTable1 != null)
                    {
                        this.xucTimekeeperTable1.BringToFront();
                        this.xucTimekeeperTable1.SetTimeKeeperTableList(tID, year);
                        this.xucTimekeeperTable1.xucOrganization1.SetFocusedNode(code);
                    }
                    else
                    {
                        this.LoadTimekeeperTable1();
                        this.xucTimekeeperTable1.SetTimeKeeperTableList(tID, year);
                        this.xucTimekeeperTable1.xucOrganization1.SetFocusedNode(code);
                    }
                }
                else if (mSelected == 2)
                {
                    if (this.xucTimekeeperTableHour != null)
                    {
                        this.xucTimekeeperTableHour.BringToFront();
                        this.xucTimekeeperTableHour.SetTimeKeeperTableList(tID, year);
                        this.xucTimekeeperTableHour.xucOrganization1.SetFocusedNode(code);
                    }
                    else
                    {
                        this.LoadTimekeeperTableHour();
                        this.xucTimekeeperTableHour.SetTimeKeeperTableList(tID, year);
                        this.xucTimekeeperTableHour.xucOrganization1.SetFocusedNode(code);
                    }
                }
            };
            this.xucTimekeeperExtraPrivate.Dock = DockStyle.Fill;
            base.Controls.Add(this.xucTimekeeperExtraPrivate);
            this.xucTimekeeperExtraPrivate.BringToFront();
        }

        private void LoadTimekeeperTable()
        {
            this.xucTimekeeperTable = new HRM.CORE.xucTimekeeperTable();
            this.xucTimekeeperTable.Closed += new HRM.CORE.xucTimekeeperTable.ClosedHandler(this.xucTimekeeperTable_Closed);
            this.xucTimekeeperTable.UnShiftData += (s, m, y) => this.RaiseUnShiftDataHandler(m, y);
            this.xucTimekeeperTable.TimekeeperTableDeleted += s => this.RaiseTimekeeperTableDeletedHander();
            this.xucTimekeeperTable.TimekeeperTableHourSelected += delegate (object s, string code, Guid tID, int year, int mSelected) {
                if (mSelected == 0)
                {
                    if (this.xucTimekeeperTable1 != null)
                    {
                        this.xucTimekeeperTable1.BringToFront();
                        this.xucTimekeeperTable1.SetTimeKeeperTableList(tID, year);
                        this.xucTimekeeperTable1.xucOrganization1.SetFocusedNode(code);
                    }
                    else
                    {
                        this.LoadTimekeeperTable1();
                        this.xucTimekeeperTable1.SetTimeKeeperTableList(tID, year);
                        this.xucTimekeeperTable1.xucOrganization1.SetFocusedNode(code);
                    }
                }
                else if (mSelected == 1)
                {
                    if (this.xucTimekeeperTableHour != null)
                    {
                        this.xucTimekeeperTableHour.BringToFront();
                        this.xucTimekeeperTableHour.SetTimeKeeperTableList(tID, year);
                        this.xucTimekeeperTableHour.xucOrganization1.SetFocusedNode(code);
                    }
                    else
                    {
                        this.LoadTimekeeperTableHour();
                        this.xucTimekeeperTableHour.SetTimeKeeperTableList(tID, year);
                        this.xucTimekeeperTableHour.xucOrganization1.SetFocusedNode(code);
                    }
                }
                else if (mSelected == 2)
                {
                    if (this.xucTimekeeperExtraPrivate != null)
                    {
                        this.xucTimekeeperExtraPrivate.BringToFront();
                        this.xucTimekeeperExtraPrivate.SetTimeKeeperTableList(tID, year);
                        this.xucTimekeeperExtraPrivate.xucOrganization1.SetFocusedNode(code);
                    }
                    else
                    {
                        this.LoadTimekeeperExtraPrivate();
                        this.xucTimekeeperExtraPrivate.SetTimeKeeperTableList(tID, year);
                        this.xucTimekeeperExtraPrivate.xucOrganization1.SetFocusedNode(code);
                    }
                }
            };
            this.xucTimekeeperTable.Dock = DockStyle.Fill;
            base.Controls.Add(this.xucTimekeeperTable);
            this.xucTimekeeperTable.BringToFront();
        }

        private void LoadTimekeeperTable1()
        {
            this.xucTimekeeperTable1 = new HRM.CORE.xucTimekeeperTable1();
            this.xucTimekeeperTable1.Closed += new HRM.CORE.xucTimekeeperTable1.ClosedHandler(this.xucTimekeeperTable_Closed);
            this.xucTimekeeperTable1.UnShiftData += (s, m, y) => this.RaiseUnShiftDataHandler(m, y);
            this.xucTimekeeperTable1.TimekeeperTableDeleted += s => this.RaiseTimekeeperTableDeletedHander();
            this.xucTimekeeperTable1.TimekeeperTableHourSelected += delegate (object s, string code, Guid tID, int year, int mSelected) {
                if (mSelected == 0)
                {
                    if (this.xucTimekeeperTable != null)
                    {
                        this.xucTimekeeperTable.BringToFront();
                        this.xucTimekeeperTable.SetTimeKeeperTableList(tID, year);
                        this.xucTimekeeperTable.xucOrganization1.SetFocusedNode(code);
                    }
                    else
                    {
                        this.LoadTimekeeperTable();
                        this.xucTimekeeperTable.SetTimeKeeperTableList(tID, year);
                        this.xucTimekeeperTable.xucOrganization1.SetFocusedNode(code);
                    }
                }
                else if (mSelected == 1)
                {
                    if (this.xucTimekeeperTableHour != null)
                    {
                        this.xucTimekeeperTableHour.BringToFront();
                        this.xucTimekeeperTableHour.SetTimeKeeperTableList(tID, year);
                        this.xucTimekeeperTableHour.xucOrganization1.SetFocusedNode(code);
                    }
                    else
                    {
                        this.LoadTimekeeperTableHour();
                        this.xucTimekeeperTableHour.SetTimeKeeperTableList(tID, year);
                        this.xucTimekeeperTableHour.xucOrganization1.SetFocusedNode(code);
                    }
                }
                else if (mSelected == 2)
                {
                    if (this.xucTimekeeperExtraPrivate != null)
                    {
                        this.xucTimekeeperExtraPrivate.BringToFront();
                        this.xucTimekeeperExtraPrivate.SetTimeKeeperTableList(tID, year);
                        this.xucTimekeeperExtraPrivate.xucOrganization1.SetFocusedNode(code);
                    }
                    else
                    {
                        this.LoadTimekeeperExtraPrivate();
                        this.xucTimekeeperExtraPrivate.SetTimeKeeperTableList(tID, year);
                        this.xucTimekeeperExtraPrivate.xucOrganization1.SetFocusedNode(code);
                    }
                }
            };
            this.xucTimekeeperTable1.Dock = DockStyle.Fill;
            base.Controls.Add(this.xucTimekeeperTable1);
            this.xucTimekeeperTable1.BringToFront();
        }

        private void LoadTimekeeperTableHour()
        {
            this.xucTimekeeperTableHour = new HRM.CORE.xucTimekeeperTableHour();
            this.xucTimekeeperTableHour.Closed += new HRM.CORE.xucTimekeeperTableHour.ClosedHandler(this.xucTimekeeperTable_Closed);
            this.xucTimekeeperTableHour.UnShiftData += (s, m, y) => this.RaiseUnShiftDataHandler(m, y);
            this.xucTimekeeperTableHour.TimekeeperTableDeleted += s => this.RaiseTimekeeperTableDeletedHander();
            this.xucTimekeeperTableHour.TimekeeperTableSelected += delegate (object s, string code, Guid tID, int year, int mSelected) {
                if (mSelected == 0)
                {
                    if (this.xucTimekeeperTable != null)
                    {
                        this.xucTimekeeperTable.BringToFront();
                        this.xucTimekeeperTable.SetTimeKeeperTableList(tID, year);
                        this.xucTimekeeperTable.xucOrganization1.SetFocusedNode(code);
                    }
                    else
                    {
                        this.LoadTimekeeperTable();
                        this.xucTimekeeperTable.SetTimeKeeperTableList(tID, year);
                        this.xucTimekeeperTable.xucOrganization1.SetFocusedNode(code);
                    }
                }
                else if (mSelected == 1)
                {
                    if (this.xucTimekeeperTable1 != null)
                    {
                        this.xucTimekeeperTable1.BringToFront();
                        this.xucTimekeeperTable1.SetTimeKeeperTableList(tID, year);
                        this.xucTimekeeperTable1.xucOrganization1.SetFocusedNode(code);
                    }
                    else
                    {
                        this.LoadTimekeeperTable1();
                        this.xucTimekeeperTable1.SetTimeKeeperTableList(tID, year);
                        this.xucTimekeeperTable1.xucOrganization1.SetFocusedNode(code);
                    }
                }
                else if (mSelected == 2)
                {
                    if (this.xucTimekeeperExtraPrivate != null)
                    {
                        this.xucTimekeeperExtraPrivate.BringToFront();
                        this.xucTimekeeperExtraPrivate.SetTimeKeeperTableList(tID, year);
                        this.xucTimekeeperExtraPrivate.xucOrganization1.SetFocusedNode(code);
                    }
                    else
                    {
                        this.LoadTimekeeperExtraPrivate();
                        this.xucTimekeeperExtraPrivate.SetTimeKeeperTableList(tID, year);
                        this.xucTimekeeperExtraPrivate.xucOrganization1.SetFocusedNode(code);
                    }
                }
            };
            this.xucTimekeeperTableHour.Dock = DockStyle.Fill;
            base.Controls.Add(this.xucTimekeeperTableHour);
            this.xucTimekeeperTableHour.BringToFront();
        }

        public void LoadTimekeeperTableList()
        {
            if (this.xucTimekeeperTable != null)
            {
                this.xucTimekeeperTable.LoadTimeKeeperTableList();
            }
            if (this.xucTimekeeperTable1 != null)
            {
                this.xucTimekeeperTable1.LoadTimeKeeperTableList();
            }
            if (this.xucTimekeeperTableHour != null)
            {
                this.xucTimekeeperTableHour.LoadTimeKeeperTableList();
            }
            if (this.xucTimekeeperExtraPrivate != null)
            {
                this.xucTimekeeperExtraPrivate.LoadTimeKeeperTableList();
            }
        }

        private void RaiseClosedHandler()
        {
            if (this.Closed != null)
            {
                this.Closed(this);
            }
        }

        private void RaiseTimekeeperTableDeletedHander()
        {
            if (this.TimekeeperTableDeleted != null)
            {
                this.TimekeeperTableDeleted(this);
            }
        }

        private void RaiseTimekeeperTableInsertedHander()
        {
            if (this.TimekeeperTableInserted != null)
            {
                this.TimekeeperTableInserted(this);
            }
        }

        private void RaiseUnShiftDataHandler(int Month, int Year)
        {
            if (this.UnShiftData != null)
            {
                this.UnShiftData(this, Month, Year);
            }
        }

        public void SaveBeforeClose()
        {
            if (((this.xucTimekeeperTable.dt_Timekeeper.Rows.Count > 0) && (XtraMessageBox.Show("Bạn c\x00f3 muốn lưu lại dữ liệu đ\x00e3 thay đổi kh\x00f4ng?", "Th\x00f4ng b\x00e1o", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.No)) && !this.xucTimekeeperTable.SaveData())
            {
                XtraMessageBox.Show("Lưu thất bại!");
            }
        }

        private void xfmTimekeeperTable_FormClosing(object sender, FormClosingEventArgs e)
        {
        }

        private void xfmTimekeeperTable_Load(object sender, EventArgs e)
        {
            clsTimeKeeperOption option = new clsTimeKeeperOption();
            if (option.TimeKeeperTableDefault == 0)
            {
                this.LoadTimekeeperTable();
            }
            else if (option.TimeKeeperTableDefault == 1)
            {
                this.LoadTimekeeperTable1();
            }
            else if (option.TimeKeeperTableDefault == 2)
            {
                this.LoadTimekeeperTableHour();
            }
            else if (option.TimeKeeperTableDefault == 3)
            {
                this.LoadTimekeeperExtraPrivate();
            }
        }

        private void xucTimekeeperTable_Closed(object sender)
        {
            base.Close();
        }

        public delegate void ClosedHandler(object sender);

        public delegate void TimekeeperTableDeletedHandler(object sender);

        public delegate void TimekeeperTableInsertedHandler(object sender);

        public delegate void UnShiftDataHandler(object sender, int Month, int Year);
    }
}

